package com.hawk.eye.client.logback.provider;

import ch.qos.logback.classic.spi.ILoggingEvent;
import com.fasterxml.jackson.core.JsonGenerator;
import net.logstash.logback.composite.AbstractJsonProvider;

import java.io.IOException;
import java.lang.management.ManagementFactory;

/**
 * @author zd
 */
public class PIDProvider extends AbstractJsonProvider<ILoggingEvent> {

    private final String pid;

    public PIDProvider() {
        this.pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
    }

    @Override
    public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
        generator.writeStringField("pid", pid);
    }
}
